package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Brand;
import com.nbsaas.boot.product.api.domain.response.BrandResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;
/**
* 品牌-实体对象转化成响应对象
*/

public class BrandResponseConvert  implements Converter<BrandResponse,Brand> {

    @Override
    public BrandResponse convert(Brand source) {
        BrandResponse  result = new  BrandResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }

                    try {
                        if(source.getCreator()!=null){
                            result.setCreatorName(source.getCreator().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getState()!=null){
                    Map<Integer,String> StateMap=new HashMap<>();
                        StateMap.put(-1,"禁用");
                        StateMap.put(1,"启用");
                    String label=  StateMap.get(source.getState());
                    result.setStateName(label);
                    }
                    result.setState(source.getState());
        return result;
    }

}

